    //
//  BadgesViewController.m
//  SpendFunk
//
//  Created by dongmh on 4/30/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "BadgesViewController.h"
#import "image.h"

@implementation BadgesViewController
- (id)init{
	return self;
}
- (void)loadView{
	[super loadView];
	[self initView];
}
- (void)initView{
	
	NSString *path = nil;
	UIImage *img = nil;
	
	// background
	////
	path = [[NSString alloc] initWithFormat:@"%@",IMG_HEADER];
	img = [UIImage imageNamed:path];
	UIImageView *imgvBar = [[UIImageView alloc] initWithFrame:CGRectMake(0, -22, img.size.width, img.size.height)];
	[imgvBar setImage:img];
	[self.view addSubview:imgvBar];
	[imgvBar setUserInteractionEnabled:YES];
	[imgvBar release];
	////
	[path release];
	path = [[NSString alloc] initWithFormat:@"%@",IMG_BKGR_VIEW];
	img = [UIImage imageNamed:path];
	UIImageView *imgvBkgr = [[UIImageView alloc] initWithFrame:CGRectMake(0, 25, img.size.width , img.size.height)];
	[imgvBkgr setImage:img];
	[self.view addSubview:imgvBkgr];
	[imgvBkgr setUserInteractionEnabled:YES];
	[imgvBkgr release];
	
	///
	[path release];
	path = [[NSString alloc] initWithFormat:@"%@",IMG_BTN_LOAD];
	img = [UIImage imageNamed:path];	
	m_pBtnRefresh = [[UIButton alloc] initWithFrame:CGRectMake(320-5-img.size.width, -14, img.size.width, img.size.height)];
	[m_pBtnRefresh setBackgroundImage:img forState:UIControlStateNormal];
	[m_pBtnRefresh setBackgroundColor:[UIColor clearColor]];
	m_pBtnRefresh.titleLabel.textColor = [UIColor whiteColor];
	[m_pBtnRefresh addTarget:nil action:@selector(onClickRefresh) forControlEvents:UIControlEventTouchUpInside];
	[self.view addSubview:m_pBtnRefresh];
	
	// highroller background
	[path release];
	path = [[NSString alloc] initWithFormat:@"%@",IMG_BKGR_HIGHROLLER];
	img = [UIImage imageNamed:path];
	UIImageView *imgvBadgeBkgr = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, img.size.width, img.size.height)];
	[imgvBadgeBkgr setImage:img];
	[self.view addSubview:imgvBadgeBkgr];
	[imgvBadgeBkgr setUserInteractionEnabled:YES];
	[imgvBadgeBkgr release];
	
	// avartar
	[path release];
	path = [[NSString alloc] initWithFormat:@"%@",IMG_AVARTAR_HIGHROLLER];
	img = [UIImage imageNamed:path];
	m_pImgvAvartar = [[UIImageView alloc] initWithFrame:CGRectMake(27, 8, img.size.width, img.size.height)];
	[imgvBadgeBkgr addSubview:m_pImgvAvartar];
	[m_pImgvAvartar setBackgroundColor:[UIColor redColor]];
	[m_pImgvAvartar release];
	// text
	UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(100, 20, 160, 20)];
	[lbl setBackgroundColor:[UIColor clearColor]];
	[imgvBadgeBkgr addSubview:lbl];
	[lbl setText:@"Badges Collected"];
	[lbl release];
	
	// badge 
	[path release];
	path = [[NSString alloc] initWithFormat:@"%@",IMG_BADGES];
	img = [UIImage imageNamed:path];
	m_pImgvBadge = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, img.size.width, img.size.height)];
	[m_pImgvBadge setImage:img];
	
	// badge title
	m_pLblTileBadge = [[UILabel alloc] initWithFrame:CGRectMake(0, m_pImgvBadge.frame.size.height +10, 80, 10)];
	[m_pLblTileBadge setBackgroundColor:[UIColor clearColor]];
	[m_pLblTileBadge setText:@"Badges Title" ];
	m_pLblTileBadge.font = [UIFont boldSystemFontOfSize:10];
	m_pLblTileBadge.textAlignment = UITextAlignmentCenter;
	//[m_pLblTileBadge release];
	
	
	// cotain badge and title
	m_pIntBadgeCount = 12;
	UIView *vt = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];

	for (int i =1; i <= m_pIntBadgeCount; i ++) {
		UIView	 *v = [[UIImageView alloc] initWithFrame:CGRectMake(0, 70, 80, 80)];
		
		if (i <= 4) {
			v.frame = CGRectMake((i-1)*80, 70 + ((i-1)/4)*80, vt.frame.size.width,vt.frame.size.height);
		}else{
			v.frame = CGRectMake((i%4==0?(4-1):(i%4)-1)*80, 70 + ((i-1)/4)*80, vt.frame.size.width,vt.frame.size.height);
			
		}
	// badge 
		[path release];
		path = [[NSString alloc] initWithFormat:@"%@",IMG_BADGES];
		img = [UIImage imageNamed:path];
		m_pImgvBadge = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, img.size.width, img.size.height)];
		[m_pImgvBadge setImage:img];
		
	
	// badge title
		m_pLblTileBadge = [[UILabel alloc] initWithFrame:CGRectMake(0, m_pImgvBadge.frame.size.height +10, 80, 10)];
		[m_pLblTileBadge setBackgroundColor:[UIColor clearColor]];
		[m_pLblTileBadge setText:@"Badges Title" ];
		m_pLblTileBadge.font = [UIFont boldSystemFontOfSize:10];
		m_pLblTileBadge.textAlignment = UITextAlignmentCenter;
	
		[v setBackgroundColor:[UIColor yellowColor]]; 
		[v addSubview:m_pImgvBadge];
		[v addSubview:m_pLblTileBadge];
		[imgvBadgeBkgr addSubview:v];
		[v release];
		
	}

}

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
